import Vue from "vue";

import "normalize.css/normalize.css"; // A modern alternative to CSS resets

import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "default-passive-events";

import "@/styles/index.scss"; // global css
import $myConfirm from "./components/myConfirm";

// 引入lodash插件库
import _ from "lodash"

import App from "./App";
import store from "./store";
import router from "./router";
import directive from "@/utils/directive.js";
import * as filters from "@/utils/filters.js";
import { roundFloat } from "@/utils/math.js";


Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});


import "@/icons"; // icon
import "@/permission"; // permission control

Vue.use(ElementUI, { size: "small" });
Vue.use(directive);
Vue.use($myConfirm);
// 全局组件
import ChangeGoodsInput from "@/components/ChangeGoodsInput";
Vue.component("ChangeGoodsInput", ChangeGoodsInput);

import ChangeUserInput from "@/components/ChangeUserInput";
Vue.component("ChangeUserInput", ChangeUserInput);

import TableHeaderSetting from "@/components/TableHeaderSetting";
Vue.component("TableHeaderSetting", TableHeaderSetting);



// 表格头回调韩式添加竖线
Vue.prototype.$verticaline = function({ row, column, rowIndex, columnIndex }) {
  if (columnIndex != 0 && columnIndex != row.length - 1) {
    return "verticaline";
  }
};

// 全局四舍五入方法
// Vue.prototype.$toFixed = function(number, precision = 2) {
//   const func = Math.round;
//   var _sign = number < 0 ? -1 : 1;
//   precision == null
//     ? 0
//     : precision >= 0
//     ? Math.min(precision, 292)
//     : Math.max(precision, -292);
//   if (precision) {
//     let pair = `${number}e`.split("e");
//     const value =
//       func(`${pair[0] * _sign}e${+pair[1] + precision + 12}`) * _sign;
//     pair = `${value}e`.split("e");
//     let result = +`${pair[0]}e${+pair[1] - precision - 12}`;
//     result = Math.round(result * 100) / 100;
//     return result.toFixed(2);
//   }
//   return func(number);
// };
Vue.prototype.$toFixed = function(number, precision = 2) {
  return roundFloat(number, precision);
};

Vue.config.productionTip = false;

new Vue({
  el: "#app",
  router,
  store,
  render: h => h(App)
});
